#include <iostream>
#include <vector>#include <unistd.h>
#include <cstdlib>
using namespace std;
class Solution{
public:
int maxSubArray(vector<int> &nums){
int max_num = INT32_MIN;
int result = 0;
for (int i = 0; i < nums.size(); ++i){
result += nums[i];
if (result < 0)
result = 0;
if (max_num < result)
max_num = result;}
return max_num;
}
};
#ifndef COMPILER_ONLINE
#include "header.cpp"
#endif

void Test1()
{
    // 通过定义临时对象，来完成方法的调用
    vector<int> nums = {-2, 1, -3, 4, -1, 2, 1, -5, 4};
    int ret = Solution().maxSubArray(nums);
    if (ret == 6)
    {
        std::cout << "测试通过用例1....OK!" << std::endl;
    }
    else
    {
        std::cout << "没有通过用例1....error!" << std::endl;
    }
}

void Test2()
{
    // 通过定义临时对象，来完成方法的调用
    vector<int> nums = {-2, 1, -3, 4, -1, 2, 1, -5, 6};
    int ret = Solution().maxSubArray(nums);
    if (ret == 7)
    {
        std::cout << "测试通过用例2....OK!" << std::endl;
    }
    else
    {
        std::cout << "没有通过用例2....error!" << std::endl;
    }
}

int main()
{
    Test1();
    Test2();
    return 0;
}
